package com.chang.controller;

import com.chang.common.DataBase;
import com.jfinal.core.ActionKey;
import com.chang.BaseController;
import com.mongodb.BasicDBObject;
import org.bson.Document;

import java.util.Date;
import java.util.List;

public class Login extends BaseController {

    @ActionKey("/")
    public void index(){
        ReturnPage("/index.jsp","");
    }
    @ActionKey("/Login")
    public void login(){
        ReturnPage("jsp/admin-login.jsp","");
    }
    @ActionKey("/Login/login")
    public void loginInfo(){
       String name=getPara("account");
       String password=getPara("password");
       BasicDBObject FilterObject = new BasicDBObject().append("$and",
                new BasicDBObject[]{
                        new BasicDBObject("account",name),
                }
        );
       List<Document> UserList = DataBase.find("admin", FilterObject, null);
       if (UserList!=null&&UserList.size()>0){
           String passwordOld = UserList.get(0).get("password").toString();
           if (passwordOld.equals(password)){
               ReturnPage("/jsp/admin-main.jsp","");
           }else {
               setAttr("LoginMessage","密码错误");
               ReturnPage("jsp/admin-login.jsp","");
           }
       }else {
           setAttr("LoginMessage","用户不存在");
           ReturnPage("jsp/admin-login.jsp","");
       }
    }
}
